﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using WBGModel;
using System.Data;

namespace WBGDal
{
    public class DalConfig
    {

        public ModelConfig Carregar()
        {
            String cmd = "SELECT * FROM Config";
            return ConvertToObject(UtilBanco.ExecComRetorno(cmd));
        }

        private ModelConfig ConvertToObject(DataTable resultSet)
        {
            DataRow dr = resultSet.Rows[0];
            ModelConfig config = new ModelConfig();
            config.padraoDiasLocacao = Convert.ToInt16(dr["padraoDiasLocacao"]);
            config.webQtdNoticias = Convert.ToInt16(dr["webQtdNoticias"]);
            return config;
        }

        public void Alterar(ModelConfig obj)
        {
            string cmd = String.Format("UPDATE Config SET padraoDiasLocacao='{0}', webQtdNoticias={1}", obj.padraoDiasLocacao, obj.webQtdNoticias);
            UtilBanco.ExecSemRetorno(cmd);
        }
    }
}
